using Mono.Cecil.Cil;

namespace Cil.Ast;

public class IsInstanceExpression : SingleInstructionExpression
{
	public const int InstancePos = 0;
	public const int MaxNodes = 1;

	public IsInstanceExpression(Context context, Instruction position, Expression exp_instance)
		: base(context, position)
	{
		// base class
		ReadsStack = 1;
		WritesStack = 1;
		Nodes = new FixedList<Expression>(MaxNodes);
		ReturnType = Context.MakeRef<bool>();

		// this
		InstanceExpression = exp_instance;
	}

	public Expression InstanceExpression  { get { return Nodes[InstancePos]; } set { Nodes[InstancePos] = value; value.ParentNode = this; } }

	public override string ToString()
	{
		return string.Format("{0} is {1}", InstanceExpression, ReturnType);
	}
}

public static partial class IlAst
{
	public static IsInstanceExpression IsInstanceOf(Context context, Instruction position, Expression exp_instance)
	{
		return new IsInstanceExpression(context, position, exp_instance);
	}
}